package com.ld.security.server.admin.auth;


import com.ld.security.common.mybatis.base.vo.DataVo;
import com.ld.security.server.admin.modules.gl.api.GlFileApi;
import com.ld.security.server.admin.modules.gl.vo.UploadVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


@Api(tags = "文件上传")
@RestController
@RequestMapping("/upload")

class UploadApi {



    @Autowired
    GlFileApi api;



    @ApiOperation("vue资源上传")
    @RequestMapping(value="/vue",method = RequestMethod.POST)
    public DataVo vue(MultipartFile multipartFile) throws IOException {
        return api.vue(multipartFile);
    }

    @ApiOperation("服务器内部文件上传")
    @RequestMapping(value="/rpc/pub",method = RequestMethod.POST)
    public DataVo rpcPub(@RequestPart(value = "file") MultipartFile multipartFile) throws IOException {

        return uploadFile(multipartFile);
    }

    @ApiOperation("用户文件上传")
    @RequestMapping(value="/pub",method = RequestMethod.POST)
    public DataVo pub( MultipartFile multipartFile) throws IOException {
        return uploadFile(multipartFile);
    }




    @ApiOperation("文件下载")
    @RequestMapping(value="/downloadFile",method = RequestMethod.GET)
    @SneakyThrows
    public void downloadFile(String id){
       api.downloadFile(id);
    }

    public DataVo uploadFile(MultipartFile multipartFile) throws IOException {
       return api.uploadFile(multipartFile);

    }

}
